<%@page import="entities.User"%>
<%@page import="auxilary.Links"%>
<%@page import="auxilary.Actions"%>
<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<%
	User user = (User)request.getSession().getAttribute("user");
	boolean loggedIn = (user != null);
%>
<jsp:include page="/frames/start.jsp" />
	<%=Links.Scripts.INDEX %>
<jsp:include page="/frames/frame.jsp" />
			<h1>Home</h1>
		   <% if (!loggedIn) { %>
		   	<div class="logged-out">
				<div class="login">
					<h2>Login</h2>
					<form action="javascript:login('login-form')" class="login-form">
						<input type="text" name="username" placeholder="username" />
						<input type="password" name="password" placeholder="password" />
						<input type="hidden" name="action" value="<%=Actions.User.LOGIN %>" />
						<center><div id="login-form-error" class="error"></div></center>
						<input type="submit" value="Login" />
					</form>
				</div>
				<a id="show-register" class="show" href="javascript:switchBoxes();">New user? Register here</a>
				<div class="register">
					<h2>Register</h2>
					<form action="javascript:register()" class="register-form">
						<input type="text" name="username" placeholder="username" />
						<input type="password" name="password" placeholder="password" />
						<input type="password" name="rePassword" placeholder="re-enter password" />
						<input type="text" name="firstName" placeholder="first name" />
						<input type="text" name="lastName" placeholder="last name" />
						<input type="text" name="email" placeholder="email" />
						<input type="text" name="phone" placeholder="phone number" />
						<input type="text" name="faculty" placeholder="faculty" />
						<input type="text" name="semester" placeholder="semester" />
						<input type="hidden" name="action" value="<%=Actions.User.REGISTER %>" />
						<input id="adminCode" class="hidden" type="password" name="adminCode" placeholder="Admin code (Optional)" />
						<a id="showAdminCode" href="javascript:showAdminCode()">Have the secret Admin code?</a>
						<center><div id="register-error" class="error"></div></center>
						<input type="submit" value="Register" />
					</form>
				</div>
				<a id="show-login" class="show" href="javascript:switchBoxes();">Already have a user? Login here</a>
			</div>
		   <% } %>
			<div class="panel-box <% if (loggedIn) { %> full<% } %>">
			   <% if (loggedIn) { %>
				<div class="panel" onclick="window.location.href='<%=Links.Pages.SCHEDULE %>'"><div class="title">My Schedule</div><div id="schedule" class="panel-image"></div></div>
				<div class="panel" onclick="window.location.href='<%=Links.Pages.WISHLIST %>'"><div class="title">My Wishlist</div><div id="wish-list" class="panel-image"></div></div>
				<div class="panel" onclick="window.location.href='<%=Links.Pages.USER_COURSES %>'"><div class="title">My Courses</div><div id="course-list" class="panel-image"></div></div>
				<div class="panel"onclick="window.location.href='<%=Links.Pages.PROFILE %>'"><div class="title">My Profile</div><div id="profile" class="panel-image"></div></div>
			   <% } %>
			   <% if (!loggedIn) { %>
			   	<div id="show-register-panel" class="panel" onclick="window.location.href='javascript:switchBoxes()'"><div class="title">Register</div><div id="register" class="panel-image"></div></div>
			   	<div id="show-login-panel" class="panel" onclick="window.location.href='javascript:switchBoxes()'"><div class="title">Login</div><div id="login" class="panel-image"></div></div>
			   <% } %>
				<div class="panel" onclick="window.location.href='<%=Links.Pages.COURSES_BASE %>'"><div class="title">All Courses</div><div id="courses" class="panel-image"></div></div>
				<div class="panel"  onclick="window.location.href='<%=Links.Pages.SEARCH %>'"><div class="title">Search For Courses</div><div id="search" class="panel-image"></div></div>
			   <% if ((loggedIn) && (user.isAdmin())) { %>
				<div class="panel" onclick="window.location.href='<%=Links.Pages.USERS_BASE %>'"><div class="title">All Users</div><div id="users" class="panel-image"></div></div>
				<div class="panel" onclick="window.location.href='<%=Links.Pages.NEW_COURSE %>'"><div class="title">Create New Course</div><div id="new-course" class="panel-image"></div></div>
			   <% } %>
			</div>
			<br /><br />
			<div id="links">
				<a href="<%=Links.Pages.HELP %>">help</a> <a href="<%=Links.Pages.ABOUT %>">about</a>
			</div>
			<% if (!loggedIn) { %>
				<form class="secret" action="javascript:handleDB()">
					<a href="javascript:showSecretCode()">secret initialize database button</a>
					<input type="password" id="secret-code"/>
					<input type="hidden" id="restart-action" value="<%=Actions.User.DB_RESTART %>"/>
					<input type="hidden" id="default-action" value="<%=Actions.User.DB_DEFAULT %>"/>
				</form>
			<% } %>
<jsp:include page="/frames/end.jsp" />
